/*
    std::count 和 std::count_if
*/

#include <iostream>
#include <algorithm>
#include <vector>

int main(int argc, char const *argv[])
{
    /* code */
    srand(time(0));
    std::vector<int> vector{};
    for (int i = 0; i < 20; i++)
    {
        vector.push_back(rand() % 10);
    }

    std::for_each(vector.begin(), vector.end(), [](const int &i)
                  { std::cout << i << " "; });
    std::cout << std::endl;

    int count5 = std::count(vector.begin(), vector.end(), 5);
    std::cout << count5 << std::endl;

    int count_even = std::count_if(vector.begin(), vector.end(), [](const int &i)
                                   { return i % 2 == 0; });
    std::cout << count_even << std::endl;

    return 0;
}
